#include "recboxitem.h"
#include "ui_recboxitem.h"

recBoxItem::recBoxItem(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::recBoxItem)
{
    ui->setupUi(this);
    ui->recMusicImageBox->installEventFilter(this);
    this->move(9,9);

}

recBoxItem::~recBoxItem()
{
    delete ui;
}

bool recBoxItem::eventFilter(QObject *watched, QEvent *event)
{
//    qDebug()<<ui->recMusicImageBox->x();
//    qDebug()<<" ";
//     qDebug()<<ui->recMusicImageBox->y();
    if(watched==ui->recMusicImageBox)
    {
        if(event->type()==QEvent::Enter)  //鼠标进入事件
        {
            QPropertyAnimation *anime=new QPropertyAnimation(ui->recMusicImageBox,"geometroy");
            anime->setDuration(200);
//            anime->setStartValue(QRect(ui->recMusicImageBox->x(),ui->recMusicImageBox->y(),ui->recMusicImageBox->width(),ui->recMusicImageBox->height()));
//            anime->setEndValue(QRect(ui->recMusicImageBox->x(),ui->recMusicImageBox->y()-10,ui->recMusicImageBox->width(),ui->recMusicImageBox->height()));
            anime->setStartValue(QRect(9,9,ui->recMusicImageBox->width(),ui->recMusicImageBox->height()));
            anime->setEndValue(QRect(9,15,ui->recMusicImageBox->width(),ui->recMusicImageBox->height()));
            anime->start();

            connect(anime,&QPropertyAnimation::finished,this,[=](){
                delete anime;
            });
        }
        else if(event->type()==QEvent::Leave)  //鼠标离开事件
        {
            QPropertyAnimation *anime=new QPropertyAnimation(ui->recMusicImageBox,"geometry");
            anime->setDuration(200);
            //anime->setStartValue(QRect(ui->recMusicImageBox->x(),ui->recMusicImageBox->y(),ui->recMusicImageBox->width(),ui->recMusicImageBox->height()));
            //anime->setEndValue(QRect(ui->recMusicImageBox->x(),ui->recMusicImageBox->y()+10,ui->recMusicImageBox->width(),ui->recMusicImageBox->height()));
            anime->setStartValue(QRect(9,15,ui->recMusicImageBox->width(),ui->recMusicImageBox->height()));
            anime->setEndValue(QRect(9,9,ui->recMusicImageBox->width(),ui->recMusicImageBox->height()));
            anime->start();

            connect(anime,&QPropertyAnimation::finished,this,[=](){
                delete anime;
            });
        }
        return true;
    }
    return QObject::eventFilter(watched,event);
}

void recBoxItem::setRecText(const QString &text)
{
    ui->recMusicText->setText(text);
}

void recBoxItem::setRecImage(const QString &imagePath)
{
    QString style="border-image:url("+imagePath+")";
    ui->recMusicImage->setStyleSheet(style);
}
